/*
 * AffixHClass.java
 *
 * Created on November 5, 2007, 7:43 AM
 *
 */
package OLDSTUFF.HierarchyPackage.AffixHierarchies;

import OLDSTUFF.HierarchyPackage.*;

/**
 *
 * @author Martin Haulrich
 */
public abstract class AffixHClass implements HClass {

    /**
     * Affix that identifies this affix-Classification
     */
    public final String affix;

    /**
     * AffixHierarchy that this class belongs to.
     */
    final AffixHierarchy hier;

final int hash;
    
    
    /**
     * Constructor
     * @param hier AffixHierarchy that this class belongs to.
     * @param affix Affix that identifies this class
     */
    AffixHClass(AffixHierarchy hier, String affix) {
        this.hier = hier;
        this.affix = affix;
        hash = affix.hashCode();
    }


    /**
     * Returns ID for this class.
     * @return Affix that identifies the class.
     */
    public synchronized String getID() {
        return affix;
    }


    @Override
    public String getName() throws HierarchyException {
        return hier.getName(this);
    }


    @Override
    public Hierarchy belongsTo() {
        return hier;
    }


    @Override
    public int hashCode() {
        //return affix.hashCode();
        return hash;
    }


    @Override
    public boolean equals(Object o) {
        if (o instanceof AffixHClass) {
            return ((AffixHClass) o).affix.equals(affix);
            //return ((AffixHClass) o).affix == affix);
        //return ((AffixHClass) o).getID().equals(affix);
        }
        return false;
    }
}
